package com.linyx.simpleboot.service.impl;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.ibatis.session.SqlSessionFactory;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ResourceUtils;

import org.w3c.dom.*;

import com.alibaba.dubbo.config.annotation.Service;


@Service
public class ss {
	public static List<File> files =new ArrayList<File>();
	
	public static Set<String> set =new HashSet<String>();
	
	@Autowired 
	private SqlSessionFactory sqlSessionFactory; 
	
//	public static void main(String args[]) throws FileNotFoundException {
//		set.add("insert");
//		set.add("delete");
//		set.add("update");
//		set.add("select");
//
//		String rootpath = ResourceUtils.getURL("classpath:").getPath();
//
//		File file = new File(rootpath);		//获取其file对象
//		 func(file);
//
//		for(File ff :files) {
//		String filename =	ff.getName();
//			if(filename.contains(".xml")) {
//				try {
//				scan_xml(ff.getAbsolutePath(),set);
//				}catch (Exception e) {
//					// TODO: handle exception
//				}
//			}
//
//		}
//	}
	
	
	private  Map<String, String> scan_service() {
		return null;
	}
	
	private static   void scan_xml(String path, Set<String> set) throws DocumentException {
		
		System.out.println(path);
		
		SAXReader reader =new SAXReader();
		Document document=reader.read(path);
		Element root =document.getRootElement();
		List<Element> list = root.elements();
		for(Element object:list) {
			if(set.contains(object.getName())) {
				System.out.println(object.attributeValue("id"));
				System.out.println(object.getName()+":"+object.getText());
			}
		}
	
	}
	
	private  Map<String, String> scan_ConfigId() {
		return null;
	}
	
	private static List<File> func(File file){
		File[] fs = file.listFiles();
		for(File f:fs){
			if(f.isDirectory())	//若是目录，则递归打印该目录下的文件
				func(f);
			if(f.isFile())		//若是文件，直接打印
				files.add(f);
//				System.out.println(f);
		}
		return files;
	}

	




}
